package com.itheima.homework5;

import java.util.concurrent.CountDownLatch;

public class Demo5_CountDownLatch {
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch cd = new CountDownLatch(3);
        new Thread(()->{
            for (int i = 1; i <= 10; i++) {
                System.out.println(Thread.currentThread().getName()+"在吃"+i+"个饺子");
            }
            cd.countDown();
        },"悟天").start();
        new Thread(()->{
            for (int i = 1; i <= 15; i++) {
                System.out.println(Thread.currentThread().getName()+"在吃"+i+"个饺子");
            }
            cd.countDown();
        },"悟饭").start();
        new Thread(()->{
            for (int i = 1; i <= 20; i++) {
                System.out.println(Thread.currentThread().getName()+"在吃"+i+"个饺子");
            }
            cd.countDown();
        },"悟空").start();
        Thread.sleep(1000);
        new Thread(()->{
            try {
                cd.await();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName()+"收拾碗筷");
            cd.countDown();
        },"琪琪").start();
    }
}
